
package bw.hackathon.ub;

import java.util.Random;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class TestPage9 extends Activity{
	
	private EditText enterNum;
	private int correct =  42;
	private int result;
	private int count;
	private Integer Pid=0;
	
	
	@Override
	   public void onCreate(Bundle savedInstanceState) 
	   {
	      super.onCreate(savedInstanceState); // call super's onCreate
	      setContentView(R.layout.testpage9); // inflate the UI

	      enterNum = (EditText) findViewById(R.id.editText9);
	      final Bundle extras = getIntent().getExtras();
	      
	      
	      if(extras!=null)
	      {
	    	  count=(extras.getInt("count"))+1;
	    	  result=extras.getInt("result");
	    	  Pid=extras.getInt("Pid");
	      }
//	      enterNum.setText(Integer.toString(count));
	      Button buttonNextPage = 
	    		  (Button) findViewById(R.id.button17);
	      buttonNextPage.setOnClickListener(new View.OnClickListener()
	      {
	    	  public void onClick(View view){
	    		  
	    		  EditText enterNum = (EditText) findViewById(R.id.editText9);
	    		  String checkNum = enterNum.getText().toString();
	    		  if(checkNum == null || checkNum.equals("")){
	    		      Toast.makeText(getApplicationContext(),
	    		    		  "Please Enter A Number", Toast.LENGTH_SHORT).show();
	    		  }
	    		  int input = Integer.parseInt(enterNum.getText().toString());
	    		  if(input==correct){
	    			result = result + 1;
	    		  } 
	    		  if(count >9){
	    			  Intent intent1 = new Intent(view.getContext(), CompleteTest.class);
	    			  startActivity(intent1);
	    		  }
	    		  
	    		  else{
	    			  randomizer(); 
	    		  }
	      }
	      });
	      
	    
	      
	      
	      Button buttonNextPage1 = 
	    		  (Button) findViewById(R.id.button18);
	      buttonNextPage1.setOnClickListener(new View.OnClickListener()
	      {
	    	  public void onClick(View view){
	    		  if(count >9){
	    			  Intent intent = new Intent(view.getContext(), CompleteTest.class);
	    			  startActivity(intent);
	    		  }
	    		  else{
	    			  randomizer(); 
	    		  }
	      }
	      });

	      
	   }
	
	private void randomizer()
	{
		Random r = new Random();
		int var=0;
		var=r.nextInt(11)+1;
		switch (var){
		
		case 1:
			Intent i = new Intent(getApplicationContext(), TestPage.class);
			i.putExtra("count", count);
			i.putExtra("result", result);
			i.putExtra("Pid", Pid);
			startActivity(i);
			break;
		case 2:
			Intent i1 = new Intent(getApplicationContext(), TestPage2.class);
			i1.putExtra("count", count);
			i1.putExtra("result", result);
			i1.putExtra("Pid", Pid);
			startActivity(i1);
			break;
		case 3:
			Intent i2 = new Intent(getApplicationContext(), TestPage3.class);
			i2.putExtra("count", count);
			i2.putExtra("result", result);
			i2.putExtra("Pid", Pid);
			startActivity(i2);
			break;
		case 4:
			Intent i3 = new Intent(getApplicationContext(), TestPage4.class);
			i3.putExtra("count", count);
			i3.putExtra("result", result);
			i3.putExtra("Pid", Pid);
			startActivity(i3);
			break;
		case 5:
			Intent i4 = new Intent(getApplicationContext(), TestPage5.class);
			i4.putExtra("count", count);
			i4.putExtra("result", result);
			i4.putExtra("Pid", Pid);
			startActivity(i4);
			break;
		case 6:
			Intent i5 = new Intent(getApplicationContext(), TestPage6.class);
			i5.putExtra("count", count);
			i5.putExtra("result", result);
			i5.putExtra("Pid", Pid);
			startActivity(i5);
			break;
		case 7:
			Intent i6 = new Intent(getApplicationContext(), TestPage7.class);
			i6.putExtra("count", count);
			i6.putExtra("result", result);
			i6.putExtra("Pid", Pid);
			startActivity(i6);
			break;
		case 8:
			Intent i7 = new Intent(getApplicationContext(), TestPage8.class);
			i7.putExtra("count", count);
			i7.putExtra("result", result);
			i7.putExtra("Pid", Pid);
			startActivity(i7);
			break;
		case 9:
			Intent i8 = new Intent(getApplicationContext(), TestPage9.class);
			i8.putExtra("count", count);
			i8.putExtra("result", result);
			i8.putExtra("Pid", Pid);
			startActivity(i8);
			break;
		case 10:
			Intent i9 = new Intent(getApplicationContext(), TestPage10.class);
			i9.putExtra("count", count);
			i9.putExtra("result", result);
			i9.putExtra("Pid", Pid);
			startActivity(i9);
			break;
		case 11:
			Intent i10 = new Intent(getApplicationContext(), TestPage11.class);
			i10.putExtra("count", count);
			i10.putExtra("result", result);
			i10.putExtra("Pid", Pid);
			startActivity(i10);
			break;
		
		}
		
	}
}